const bcrypt = require('bcryptjs')

/**
 * bcryptjs加密
 * @param {String} encryptedContent 被加密的内容
 */
function bcryptjs (encryptedContent) {
    const salt = bcrypt.genSaltSync(10)
    // hash保存的是加密后的密码
    const hash = bcrypt.hashSync(encryptedContent, salt)
    return hash
}

/**
 * bcryptjs解密
 * @param {String} doesNotDeclassify 未加密内容(即原密码)
 * @param {String} alreadyDeclassified 已加密内容(即数据库内的密码)
 */
function bcryptjsDeclassify (doesNotDeclassify, alreadyDeclassified) {
    return bcrypt.compareSync(doesNotDeclassify, alreadyDeclassified)
}

module.exports = {
    bcryptjs,
    bcryptjsDeclassify
}